<template>
  <div class="page bgc-fff">
    <x-header title="个人信息"></x-header>
    <panel header="身份证信息" align="left" style="margin-top: 0.46rem;"></panel>
    <!-- main -->
    <div class="main f12">
      <div class="flex a-around l-center pad-t30 pad-l-r10 pad-b30">
        <div>
          <v-upload-img
            class="depart-upload-img2"
            @upload-img-start='uploadImgStart'
            @upload-img-end='uploadImgEnd'
            :upload-post-data="postData"
            :upload-img-obj="uploadImgData[0]"></v-upload-img>
          <div class="upload-item-title">{{uploadImgData[0].title}}</div>
        </div>
        <div>
          <v-upload-img
            class="depart-upload-img2"
            @upload-img-start='uploadImgStart'
            @upload-img-end='uploadImgEnd'
            :upload-post-data="postData"
            :upload-img-obj="uploadImgData[1]"></v-upload-img>
          <div class="upload-item-title">{{uploadImgData[1].title}}</div>
        </div>
      </div>
      <div class="flex a-around l-center pad-l-r10 pad-b30">
        <div>
          <v-upload-img
            class="depart-upload-img2"
            @upload-img-start='uploadImgStart'
            @upload-img-end='uploadImgEnd'
            :upload-post-data="postData"
            :upload-img-obj="uploadImgData[2]"></v-upload-img>
          <div class="upload-item-title">{{uploadImgData[2].title}}</div>
        </div>
        <div class="upload-item-box" style="width:1.62rem;height:1.31rem;">
        </div>
      </div>
      <!--<div class="upload-title">-->
        <!--驾驶证信息-->
      <!--</div>-->
      <panel header="驾驶证信息" align="left"></panel>
      <div class="flex a-around l-start pad-l-r10 pad-t30 pad-b30 bor-bottom">
        <div>
          <v-upload-img
            class="depart-upload-img2"
            @upload-img-start='uploadImgStart'
            @upload-img-end='uploadImgEnd'
            :upload-post-data="postData"
            :upload-img-obj="uploadImgData[3]"></v-upload-img>
          <div class="upload-item-title">{{uploadImgData[3].title}}</div>
        </div>
        <div>
          <v-upload-img
            class="depart-upload-img"
            @upload-img-start='uploadImgStart'
            @upload-img-end='uploadImgEnd'
            :upload-post-data="postData"
            :upload-img-obj="uploadImgData[4]"></v-upload-img>
          <div class="upload-item-title">{{uploadImgData[4].title}}</div>
        </div>

      </div>
      <!-- title -->
      <!-- style="height:.16rem;line-height:.16rem;" -->
      <div  class="pad-l-r15 pad-t15 pad-b15 ta-c f12"  :class="[{'red':!isLicenseCheckSuc}]">{{text1}}</div>
      <!-- input -->
      <div class="input-cells bor-bottom input-name">
        <div class="f-fl input-label">真实姓名</div>
        <div v-if="driverParam.name  && isLicenseCheckSuc && dNameShow" class="text-show-block">{{driverParam.name}}</div>
        <input v-else type="text" class="cell-input" placeholder="请输入姓名"
               @blur="nameHaveChange" v-model.trim="driverLicenseInfo.owner" />
      </div>
      <div class="input-cells sex-select bor-bottom">
        <div class="f-fl input-label">性别</div>
        <!-- <v-radio-row :radioData='sexSelect' @sex-radio="sexRadioSelect"></v-radio-row> -->
        <div v-if="text2 && isLicenseCheckSuc && dSexShow" class="text-show-block">{{text2}}</div>
        <div v-else class="select-radio">
          <div class="select-radio-item" v-for="(item,index) in sexSelect.optionss"
               :key="index" :class="[{'mr5':index==0}]" >
            <em @click="sexRadioClick(index)" class="select-radio-item-q"
                :class="[{'active':index==sexSelect.sexIndex}]">
              <i></i>
            </em>
            <span>{{item.value}}</span>
          </div>
        </div>
      </div>
      <!-- input -->
      <div class="input-cells input-phone bor-bottom">
        <div class="f-fl input-label">手机号</div>
        <!-- <input type="tel" class="cell-input"   placeholder="请输入手机号"
                  maxlength="11" v-model.trim="driverParam.mobile"  /> -->
        <div class="text-show-block">{{driverParam.mobile}}</div>
      </div>
      <div class="input-cells input-idcard bor-bottom">
        <div class="f-fl input-label">驾驶证/身份证号</div>
        <div v-if="driverParam.driverLicenseId && isLicenseCheckSuc && dDriverLicenseIdShow" class="text-show-block">{{driverParam.driverLicenseId}}</div>
        <input v-else  type="text" class="cell-input"   placeholder="请输入身份证号"
               @blur="licenseIdHaveChange"    maxlength="18" v-model.trim="driverLicenseInfo.licenseId"  />
      </div>
      <div class="input-cells input-idcard bor-bottom" >
        <div class="f-fl input-label">初次发证日期</div>
        <div v-if="driverParam.driverLicenseFirstDate && isLicenseCheckSuc && dLicenseInitDateShow" class="text-show-block">{{driverParam.driverLicenseFirstDate | formatDate}}</div>
        <input v-else  type="text" class="cell-input"
               placeholder="请输入初次发证日期" @click="pickerDate('initdate')"
               v-model.trim="driverLicenseInfo.licenseInitDate" />
      </div>
      <div class="input-cells input-idcard bor-bottom">
        <div class="f-fl input-label">有效开始日期</div>
        <div v-if="driverParam.driverLicenseStartDate && isLicenseCheckSuc && dLicenseStartDateShow" class="text-show-block">{{driverParam.driverLicenseStartDate | formatDate}}</div>
        <input v-else  type="text" class="cell-input"
               placeholder="请输入有效开始日期" @click="pickerDate('startdate')"
               v-model.trim="driverLicenseInfo.licenseStartDate" />
      </div>
      <div class="input-cells input-idcard bor-bottom">
        <div class="f-fl input-label">有效截止日期</div>
        <div v-if="driverParam.driverLicenseEndDate&& isLicenseCheckSuc && dLicenseEndDateShow" class="text-show-block">{{driverParam.driverLicenseEndDate | formatDate}}</div>
        <input v-else type="text" class="cell-input"
               placeholder="请输入有效截止日期" @click="pickerDate('enddate')"
               v-model.trim="driverLicenseInfo.licenseEndDate" />
      </div>
      <div class="input-cells input-idcard ">
        <div class="f-fl input-label">驾驶证类型</div>
        <div v-if="driverParam.drivingLicenseType && isLicenseCheckSuc && dLicenseTypeShow" class="text-show-block">{{driverParam.drivingLicenseType}}</div>
        <input v-else type="text" class="cell-input" placeholder="请输入驾驶证类型"
               @blur="licenseTypeHaveChange"  v-model.trim="driverLicenseInfo.licenseType" />
      </div>
      <!-- button -->
      <div class="pad-l-r15 pad-t30">
        <p class="large-btn" :disabled="subBtnDisabled"
           :class="[{'bgc-01a4f6':!subBtnDisabled}]"
           @click="subButton">提交</p>
      </div>
      <div style="height:.15rem;"></div>
    </div>

    <!-- datetime-picker -->
    <mt-datetime-picker
      ref="datepicker"
      v-model="pickerVisible"
      type="date"
      :startDate="licenseStartDateVal"
      :endDate="licenseEndDateVal"
      year-format="{value} 年"
      month-format="{value} 月"
      date-format="{value} 日"
      @confirm="handleConfirm">
    </mt-datetime-picker>

    <v-loading  ref="changeLoadingVal" v-show="loadingShow" :loadingval="loadingVal" style="z-index:11" ></v-loading>

  </div>
</template>

<script type="text/ecmascript-6">
  import '@/styles/downPicker.css'
  import * as DriverApi from '@/api/dirver'
  import { getToken } from '@/api/qiniu'
  import { XHeader, Panel } from 'vux'
  import { Toast, DatetimePicker } from 'mint-ui'
  import Utils from '@/utils/util'
  import * as DevopApi from '@/api/devop'
  import * as QiniuApi from '@/api/qiniu'
  import * as ThreeStorage from '@/utils/store/token.js' // cookie local session 统一管理
  import UploadImg from '@/components/common/uploadImg/upload_type_one'
  import Loading from '@/components/common/loading/loading'
  const QINIU_API = process.env.QINIU_API // 'http://up-z2.qiniu.com/' https://qiniu.lisa-test.unlcn.com/
  export default {
    name: 'me-driverProfile',
    data() {
      return {
        loadingVal: '正在加载中...',
        staticImgData: {
          imgurla: require('@/assets/image/common/user.png')
        },
        postData: {
          token: '',
          imageUrl: QINIU_API,
          key: ''
        },
        uploadImgData: [
          {
            fileMark: 'idCard',
            title: '身份证正面',
            licenseTypeId: '1',
            attachTypeId: '01',
            attachDemoImgSrc: require('@/assets/image/v1/upload_examples_img/licenseId.png'),
            attachImgSrc: ''
          },
          {
            fileMark: 'reverseIdCard',
            title: '身份证反面',
            licenseTypeId: '1',
            attachTypeId: '02',
            attachDemoImgSrc: require('@/assets/image/v1/upload_examples_img/licenseid_reverse.png'),
            attachImgSrc: ''
          },
          {
            fileMark: 'withIdCard',
            title: '手持身份证',
            licenseTypeId: '1',
            attachTypeId: '03',
            attachDemoImgSrc: require('@/assets/image/v1/upload_examples_img/withIdCard.png'),
            attachImgSrc: ''
          },
          {
            fileMark: 'driverLicense',
            title: '驾驶证正面',
            licenseTypeId: '2',
            attachTypeId: '01',
            attachDemoImgSrc: require('@/assets/image/v1/upload_examples_img/dirver_licenseId.png'),
            attachImgSrc: ''
          },
          {
            fileMark: 'operatingLicense',
            title: '从业资格证正面',
            licenseTypeId: '3',
            attachTypeId: '01',
            attachDemoImgSrc: require('@/assets/image/v1/upload_examples_img/dirver_operatingLicense.png'),
            attachImgSrc: ''
          }
        ],
        driverParam: {
          id: '', // 司机id
          name: '',
          mobile: '', // 手机号
          dob: '',
          licenseId: '', // 身份证
          sex: 0,
          idCardKey: '',
          idCardPath: '',
          idCardAttachName: '',
          withIdCardKey: '', // 手持身份证
          withIdCardPath: '',
          withIdCardAttachName: '',
          reverseIdCardKey: '', // 身份证反面
          reverseIdCardPath: '',
          reverseIdCardAttachName: '',
          driverLicenseKey: '', // 驾驶证七牛hash
          driverLicensePath: '', // 驾驶证七牛资源路径
          driverLicenseAttachName: '', // 驾驶证七牛图片名
          operatingLicenseKey: '',
          operatingLicensePath: '',
          operatingLicenseAttachName: '',
          driverLicenseId: '', // 驾驶证编号
          drivingLicenseType: '', // 驾驶证类型c1
          driverLicenseFirstDate: '',
          driverLicenseStartDate: '', // 驾驶证有效期开始
          driverLicenseEndDate: ''
        },
        driverLicenseInfo: {
          owner: '', // 姓名
          sex: '',
          licenseId: '', // 驾驶证编号
          licenseType: '', // 驾驶证类型c1
          licenseInitDate: '', // 第一次领证时间
          licenseStartDate: '', // 驾驶证有效期开始
          licenseEndDate: ''
        },
        isLicenseCheckSuc: true,
        text1: '', // picker标题
        text2: '', // 男 女
        chooseVal: '', // 那个时间进行picker调用
        sexSelect: {
          sexIndex: 0,
          selectValue: '',
          optionss: [
            { id: 0, value: '女' },
            { id: 1, value: '男' }
          ]
        },
        resDirverData: {},
        dirverId: '',
        loadingShow: false,
        isHaveValNull: false, // 司机信息是否有空
        isLicenseInfoHaveValNull: false, // 驾驶证信息是否有空
        licenseStartDateVal: new Date(String(new Date().getFullYear() - 100)),
        licenseEndDateVal: new Date(String(new Date().getFullYear() + 100)),
        pickerVisible: new Date(), // 时间picker值
        dNameShow: false,
        dSexShow: false,
        dDriverLicenseIdShow: false, // 驾驶证
        dLicenseInitDateShow: false,
        dLicenseStartDateShow: false,
        dLicenseEndDateShow: false,
        dLicenseTypeShow: false,
        prevent_repeat: false,
        subBtnDisabled: true
      }
    },
    components: {
      XHeader, Panel, 'v-upload-img': UploadImg,
      'mt-datetime-picker': DatetimePicker,
      'v-loading': Loading
    },
    created() {
      this.getQiniuToken()
      this.getInfoInit()
    },
    filters: {
      formatDate(time) {
        const date = new Date(time)
        return Utils.formatTime(date, 'Y-M-D')
      }
    },
    methods: {
      // 初始获取用户信息 回填
      getInfoInit: function() {
        const that = this
        const dirver_id = ThreeStorage.getDriverId()
        this.dirverId = dirver_id
        DriverApi.getDriver(dirver_id).then(res => {
          if (res.code === 0) {
            const res_data = res.data
            if (res_data) {
              //  yod驾龄 dob出生时间戳  fleetId  weixinId微信id  lspId  serviceType, status, authStatus,
              const { name, mobile, sex, idCardKey, idCardPath, withIdCardKey, withIdCardPath,
                driverLicenseKey, driverLicensePath, operatingLicenseKey, operatingLicensePath,
                idCardAttachName, withIdCardAttachName, driverLicenseAttachName, operatingLicenseAttachName,
                driverLicenseId, drivingLicenseType, driverLicenseStartDate, driverLicenseEndDate,
                reverseIdCardKey, reverseIdCardPath, reverseIdCardAttachName, driverLicenseFirstDate } = res_data
              // 将需要用于判断按钮自灰的参数 另外组成 新对象
              const new_resdata = {
                name, mobile, sex, idCardKey, idCardPath, withIdCardKey, withIdCardPath,
                driverLicenseKey, driverLicensePath, operatingLicenseKey, operatingLicensePath,
                idCardAttachName, withIdCardAttachName, driverLicenseAttachName, operatingLicenseAttachName,
                driverLicenseId, drivingLicenseType, driverLicenseStartDate, driverLicenseEndDate,
                reverseIdCardKey, reverseIdCardPath, reverseIdCardAttachName, driverLicenseFirstDate
              }
              // 图片路径
              that.uploadImgData[0].attachImgSrc = idCardPath
              that.uploadImgData[1].attachImgSrc = reverseIdCardPath
              that.uploadImgData[2].attachImgSrc = withIdCardPath
              that.uploadImgData[3].attachImgSrc = driverLicensePath
              that.uploadImgData[4].attachImgSrc = operatingLicensePath
              // 性别
              that.sexSelect.sexIndex = sex
              if (sex === 1) {
                this.text2 = '男'
                this.dSexShow = true
              } else if (sex === 0) {
                this.text2 = '女'
                this.dSexShow = true
              } else {
                this.text2 = ''
                this.dSexShow = false
              }
              // Utils.isLegalObject() 合法对象
              this.dNameShow = Utils.isLegalObject(name)
              this.dDriverLicenseIdShow = Utils.isLegalObject(driverLicenseId)
              this.dLicenseInitDateShow = Utils.isLegalObject(driverLicenseFirstDate)
              this.dLicenseStartDateShow = Utils.isLegalObject(driverLicenseStartDate)
              this.dLicenseEndDateShow = Utils.isLegalObject(driverLicenseEndDate)
              this.dLicenseTypeShow = Utils.isLegalObject(drivingLicenseType)
              // 无空值 则  this.checkInfoIsNull() 返回 true
              this.isHaveValNull = this.checkInfoIsNull(new_resdata)
              if (this.isHaveValNull) {
                // 无空值则 btn 禁用自灰
                this.subBtnDisabled = true
              } else {
                this.subBtnDisabled = false
              }
              // this.isLicenseCheckSuc = true
              this.driverParam = res_data
            } else {
              Toast({
                message: '获取个人信息失败',
                duration: 2000
              })
            }
          }
        }).catch(res => {
          console.warn('error', res)
        })
      },
      // 检查对象是否有空值 =》 提交按钮是否放开
      checkInfoIsNull: function(object) {
        const new_carInfo = object
        if (new_carInfo) {
          for (const k in new_carInfo) {
            if (new_carInfo[k] !== 0) {
              // new_carInfo[k] !== 0 针对有参数值为0 ，0 会判断false ,例：sex:0 => new_carInfo[k]为false
              if (!new_carInfo[k] || new_carInfo[k] === '') {
                console.log('new_[k]其中某值为空', new_carInfo, k, new_carInfo[k])
                return false
              }
            }
          }
        } else {
          return false
        }
        return true
      },
      // 只适用于 20131112 => 2013-11-12
      changeDataStyle: function(str, flg) {
        let newstr = ''
        const tmp = str.substring(0, 4)
        const tmp2 = str.substring(4, 6)
        const tmp3 = str.substring(6, 8)
        newstr = tmp + flg + tmp2 + flg + tmp3
        // console.log('tmp', tmp, 'tmp2', tmp2, 'tmp3', tmp3, 'newstr', newstr)
        if (newstr) {
          return newstr
        } else {
          newstr = ''
          return newstr
        }
      },
      // 男 or 女
      sexRadioClick: function(index) {
        // debugger
        this.sexSelect.sexIndex = index
        const arr = this.sexSelect.optionss
        this.sexSelect.selectValue = arr[index].value
        // this.$emit('sex-radio', this.radioData.selectValue)
        const val = this.sexSelect.selectValue
        if (val === '男') {
          this.driverParam.sex = 1
        } else if (val === '女') {
          this.driverParam.sex = 0
        }
        this.subBtnDisabled = false
      },
      // 获取七牛token
      getQiniuToken: function() {
        const that = this
        getToken().then(res => {
          if (res.code === 0) {
            that.postData.token = res.data
          }
        }).catch(res => {
          console.warn('error', res)
        })
      },
      // 证件 改变
      licenseIdHaveChange: function() {
        this.subBtnDisabled = false
        this.driverParam.driverLicenseId = this.driverLicenseInfo.licenseId
        this.driverParam.licenseId = this.driverLicenseInfo.licenseId
      },
      // 证件类型 改变
      licenseTypeHaveChange: function() {
        this.driverParam.drivingLicenseType = this.driverLicenseInfo.licenseType
      },
      // 时间picker
      pickerDate: function(val) {
        this.chooseVal = val
        this.$refs.datepicker.open()
      },
      // 时间picker确认
      handleConfirm: function() {
        if (this.pickerVisible) {
          const picker_date = Utils.formatTime(this.pickerVisible, 'Y-M-D')
          const picker_date_num = Date.parse(new Date(this.pickerVisible))
          if (this.chooseVal === 'startdate') {
            this.driverParam.driverLicenseStartDate = picker_date_num
            this.driverLicenseInfo.licenseStartDate = picker_date
          } else if (this.chooseVal === 'enddate') {
            this.driverParam.driverLicenseEndDate = picker_date_num
            this.driverLicenseInfo.licenseEndDate = picker_date
          } else {
            this.driverParam.driverLicenseFirstDate = picker_date_num
            this.driverLicenseInfo.licenseInitDate = picker_date
          }
          this.subBtnDisabled = false
        }
      },
      // 手机号提示
      mobileClickAlert: function() {
        Toast({
          message: '手机号不可更改',
          duration: 1000
        })
      },
      // name输入框修改
      nameHaveChange: function() {
        this.subBtnDisabled = false
        this.driverParam.name = this.driverLicenseInfo.owner
      },
      // 图片开始上传
      uploadImgStart: function() {
        this.loadingShow = true
      },
      // 子组件-上传图片后-通知父组件
      uploadImgEnd: function(qiniuResData) {
        const that = this
        if (qiniuResData.status) {
          that.subBtnDisabled = false
          that.updateFileDataBeforeFunc(qiniuResData)
        } else {
          that.loadingShow = false
          Toast({
            message: '图片上传失败',
            duration: 1000
          })
        }
      },
      // 上传完 数据赋值
      updateFileDataBeforeFunc(qiniuResData) {
        const that = this
        this.loadingShow = false
        console.log('qiniuResData', qiniuResData)
        if (qiniuResData.uploadImgObj.fileMark === 'idCard') {
          that.driverParam.idCardKey = qiniuResData.hash
          that.driverParam.idCardAttachName = qiniuResData.imgName
        } else if (qiniuResData.uploadImgObj.fileMark === 'reverseIdCard') {
          that.driverParam.reverseIdCardKey = qiniuResData.hash
          that.driverParam.reverseIdCardAttachName = qiniuResData.imgName
        } else if (qiniuResData.uploadImgObj.fileMark === 'withIdCard') {
          that.driverParam.withIdCardKey = qiniuResData.hash
          that.driverParam.withIdCardAttachName = qiniuResData.imgName
        } else if (qiniuResData.uploadImgObj.fileMark === 'driverLicense') {
          that.driverParam.driverLicenseKey = qiniuResData.hash
          that.driverParam.driverLicenseAttachName = qiniuResData.imgName
        } else if (qiniuResData.uploadImgObj.fileMark === 'operatingLicense') {
          that.driverParam.operatingLicenseKey = qiniuResData.hash
          that.driverParam.operatingLicenseAttachName = qiniuResData.imgName
        }
        const file_info = {
          driverId: that.dirverId,
          key: qiniuResData.hash,
          keyTypeName: qiniuResData.uploadImgObj.fileMark,
          path: null,
          attachName: qiniuResData.imgName
        }
        that.updateFileDataFunc(file_info)
        console.log('that.driverParam', that.driverParam)
      },
      // 单独跟司机绑定图片key
      updateFileDataFunc: function(info) {
        const fileInfo = info
        this.loadingShow = true
        QiniuApi.updateDriverAttach(fileInfo).then(res => {
          this.loadingShow = false
          if (res.code === 0) {
            Toast({
              message: '图片上传成功',
              duration: 1000
            })
            if (fileInfo.keyTypeName === 'driverLicense') {
              this.getImgUrlFun(this.driverParam.driverLicenseKey) // 用hash 换取七牛imgurl
            }
          } else {
            Toast({
              message: '图片上传失败',
              duration: 1000
            })
          }
        }).catch(res => {
          this.loadingShow = false
          console.warn('error', res)
        })
      },
      // 上传图片成功后 七牛hash换取 七牛图片资源路径
      getImgUrlFun: function(hash) {
        const that = this
        const req_hash = hash
        const toParam = {
          key: req_hash,
          type: 'driver'
        }
        QiniuApi.getImgUrl(toParam).then(res => {
          if (res.code === 0) {
            const res_imgurl = res.data.url
            that.judgeDriverLicense(res_imgurl)
          }
        }).catch(res => {
          console.warn('error', res)
        })
      },
      // 驾照证件号识别
      judgeDriverLicense: function(imgurl) {
        const that = this
        if (imgurl) {
          const toParam = {
            imgUri: imgurl
          }
          this.loadingVal = '正在解析中...'
          setTimeout(() => {
            this.$refs.changeLoadingVal.changeVal()
            this.loadingShow = true
            DevopApi.getDriverLicense(toParam).then(res => {
              console.log('getDriverLicense', res)
              if (res.code === 0) {
                const res_data = res.data
                const { owner, sex, number, type, startdate, enddate, initialdate } = res_data
                if (startdate !== '' && enddate !== '' && initialdate !== '') {
                  const startdate_val = this.changeDataStyle(startdate, '-')
                  const enddate_val = this.changeDataStyle(enddate, '-')
                  const initdate_val = this.changeDataStyle(initialdate, '-')
                  const startdate_num = Date.parse(new Date(startdate_val))
                  const enddate_num = Date.parse(new Date(enddate_val))
                  const initdate_num = Date.parse(new Date(initdate_val))
                  that.driverParam.driverLicenseStartDate = startdate_num
                  that.driverParam.driverLicenseEndDate = enddate_num
                  that.driverParam.driverLicenseFirstDate = initdate_num
                  that.driverLicenseInfo.licenseStartDate = Utils.formatTime(startdate_num, 'Y-M-D')
                  that.driverLicenseInfo.licenseEndDate = Utils.formatTime(enddate_num, 'Y-M-D')
                  that.driverLicenseInfo.licenseInitDate = Utils.formatTime(initdate_num, 'Y-M-D')
                  this.isLicenseCheckSuc = true
                  Toast({
                    message: '驾照证号信息解析成功',
                    duration: 1500
                  })
                  that.text1 = ' '
                } else {
                  Toast({
                    message: '驾照证号信息解析失败',
                    duration: 1500
                  })
                  that.driverParam.driverLicenseStartDate = ''
                  that.driverParam.driverLicenseEndDate = ''
                  that.driverParam.driverLicenseFirstDate = ''
                  that.driverLicenseInfo.licenseStartDate = ''
                  that.driverLicenseInfo.licenseEndDate = ''
                  that.driverLicenseInfo.licenseInitDate = ''
                  this.isLicenseCheckSuc = false
                  that.text1 = '上传驾驶证识别失败！请手动完善信息或重新上传清晰证照！'
                }
                if (sex === '男') {
                  this.text2 = '男'
                  that.driverParam.sex = 1
                } else if (sex === '女') {
                  this.text2 = '女'
                  that.driverParam.sex = 0
                } else {
                  this.text2 = ''
                  that.driverParam.sex = 1
                }
                if (type) {
                  that.driverLicenseInfo.licenseType = type
                  that.driverParam.drivingLicenseType = type
                } else {
                  that.driverLicenseInfo.licenseType = ''
                  that.driverParam.drivingLicenseType = ''
                }
                if (number) {
                  that.driverParam.driverLicenseId = number
                  that.driverParam.licenseId = number
                  that.driverLicenseInfo.licenseId = number
                } else {
                  that.driverParam.driverLicenseId = ''
                  that.driverParam.licenseId = ''
                  that.driverLicenseInfo.licenseId = ''
                }
                if (owner) {
                  that.driverParam.name = owner
                  that.driverLicenseInfo.owner = owner
                } else {
                  that.driverParam.name = ''
                  that.driverLicenseInfo.owner = ''
                }
                this.subBtnDisabled = false
              } else {
                Toast({
                  message: '驾照信息识别失败',
                  duration: 1000
                })
                this.subBtnDisabled = false
                this.isLicenseCheckSuc = false
                that.driverParam.drivingLicenseType = ''
                that.driverParam.driverLicenseId = ''
                that.driverParam.licenseId = ''
                that.driverParam.driverLicenseStartDate = ''
                that.driverParam.driverLicenseEndDate = ''
                that.driverParam.driverLicenseFirstDate = ''
                this.text2 = ''
                // edit
                that.text1 = '上传驾驶证识别失败！请手动完善信息或重新上传清晰证照！'
                that.driverLicenseInfo = {
                  owner: '', // 姓名
                  sex: '',
                  licenseId: '', // 驾驶证编号
                  licenseType: '', // 驾驶证类型c1
                  licenseInitDate: '',
                  licenseStartDate: '', // 驾驶证有效期开始
                  licenseEndDate: ''
                }
                return
              }
              this.loadingShow = false
              this.loadingVal = '正在加载中...'
            }).catch(res => {
              this.loadingShow = false
              this.loadingVal = '正在加载中...'
              console.warn('error', res)
              that.driverParam.drivingLicenseType = ''
              that.driverParam.driverLicenseId = ''
              that.driverParam.driverLicenseStartDate = ''
              that.driverParam.driverLicenseEndDate = ''
              that.driverParam.driverLicenseFirstDate = ''
              that.driverParam.licenseId = ''
              that.driverParam.name = ''
              that.text2 = ''
              that.isLicenseCheckSuc = false
              // edit
              that.text1 = '上传驾驶证识别失败！请手动完善信息或重新上传清晰证照！'
              that.driverLicenseInfo = {
                owner: '', // 姓名
                sex: '',
                licenseId: '', // 驾驶证编号
                licenseType: '', // 驾驶证类型c1
                licenseInitDate: '',
                licenseStartDate: '', // 驾驶证有效期开始
                licenseEndDate: ''
              }
            })
          }, 1000)
        }
      },
      // 提交
      subButton: function() {
        const that = this
        if (!that.driverParam.sex) {
          that.driverParam.sex = 0
        }
        const check_res = that.checkParam(that.driverParam)
        if (check_res) {
          if (that.prevent_repeat) { return }
          that.prevent_repeat = true
          const regist_params = that.driverParam
          DriverApi.updateDriver(regist_params).then(res => {
            if (res.code === 0) {
              Toast({
                message: '提交成功',
                duration: 1000
              })
              this.$router.push({ name: 'me-driverLanding' })
            }
            that.prevent_repeat = false
          }).catch(res => {
            that.prevent_repeat = false
            console.warn('error', res)
          })
        }
      },
      // 提交参数预检
      checkParam: function(params) {
        const { name, mobile, licenseId, idCardKey, withIdCardKey, operatingLicenseKey,
          reverseIdCardKey, driverLicenseKey, drivingLicenseType, driverLicenseId, driverLicenseStartDate,
          driverLicenseEndDate, driverLicenseFirstDate } = params
        if (this.subBtnDisabled) {
          Toast({
            message: '请更换信息再提交',
            duration: 2000
          })
          return
        }
        if (name === '') {
          Toast({
            message: '请先填写姓名',
            duration: 2000
          })
          return
        }
        const name_res = Utils.checkRealName(name)
        if (!name_res) {
          Toast({
            message: '请先填写正确姓名',
            duration: 2000
          })
          return
        }
        const mobile_res = Utils.checkMobile(mobile)
        if (!mobile_res) {
          Toast({
            message: '请先填写正确手机号',
            duration: 2000
          })
          return
        }
        if (licenseId === '') {
          Toast({
            message: '请先填写身份证号',
            duration: 2000
          })
          return
        }
        const licenseId_res = Utils.checkIdCard(licenseId)
        if (!licenseId_res) {
          Toast({
            message: '请先填写正确身份证号',
            duration: 2000
          })
          return
        }
        if (!idCardKey) {
          Toast({
            message: '请上传身份证正面',
            duration: 2000
          })
          return
        }
        if (!withIdCardKey) {
          Toast({
            message: '请上传手持身份证',
            duration: 2000
          })
          return
        }
        if (!reverseIdCardKey) {
          Toast({
            message: '请上传身份证反面',
            duration: 2000
          })
          return
        }
        if (reverseIdCardKey === '') {
          Toast({
            message: '请上传身份证反面',
            duration: 2000
          })
          return
        }
        if (idCardKey === '') {
          Toast({
            message: '请上传身份证正面',
            duration: 2000
          })
          return
        }
        if (withIdCardKey === '') {
          Toast({
            message: '请上传手持身份证',
            duration: 2000
          })
          return
        }
        if (!driverLicenseKey) {
          Toast({
            message: '请上传驾驶证正面',
            duration: 2000
          })
          return
        }
        if (!operatingLicenseKey) {
          Toast({
            message: '请上传运营许可证',
            duration: 2000
          })
          return
        }
        if (!drivingLicenseType) {
          Toast({
            message: '请上传正确的驾照证',
            duration: 2000
          })
          return
        }
        if (!driverLicenseId) {
          Toast({
            message: '请上传正确的驾照证',
            duration: 2000
          })
          return
        }
        if (drivingLicenseType === '') {
          Toast({
            message: '请上传正确的驾照证',
            duration: 2000
          })
          return
        }
        if (driverLicenseId === '') {
          Toast({
            message: '请上传正确的驾照证',
            duration: 2000
          })
          return
        }
        if (!driverLicenseStartDate) {
          Toast({
            message: '请上传正确的驾照证',
            duration: 2000
          })
          return
        }
        if (!driverLicenseEndDate) {
          Toast({
            message: '请上传正确的驾照证',
            duration: 2000
          })
          return
        }
        if (!driverLicenseFirstDate) {
          Toast({
            message: '请上传正确的驾照证',
            duration: 2000
          })
          return
        }
        if (driverLicenseStartDate === '') {
          Toast({
            message: '请先选择有效开始日期',
            duration: 2000
          })
          return
        }
        if (driverLicenseEndDate === '') {
          Toast({
            message: '请先选择有效截至日期',
            duration: 2000
          })
          return
        }
        if (driverLicenseEndDate < driverLicenseStartDate) {
          Toast({
            message: '驾驶证有效截至日期不能小于有效起始日期',
            duration: 2000
          })
          return
        }
        return true
      }
    }
  }
</script>

<style scoped>
  @import '../../styles/util.css';
  /* common */
  .page{
    overflow-y: auto;
  }
  .input-phone.bor-bottom:after{
    bottom: 1px;
  }
  .large-btn{
    background-color: #dedede;
  }
  .large-btn.bgc-01a4f6{
    background-color: #01a4f6;
  }
  .min-btn{
    background-color: #dedede;
  }
  .min-btn.bgc-01a4f6{
    background-color: #01a4f6;
  }
  .input-name>input{
    width: 1.1rem;
  }
  .input-cells>input{
    text-align: right ;
  }
  /* .select-radio-item>span{
    font-size: .16rem;
  } */
  /* main */
  .text-show-block{
    line-height: .24rem;
    font-size: .14rem;
    overflow: hidden;
    margin-left: 0;
    line-height: .32rem;
    font-size: 0.14rem;
    text-align: right;
  }
  /*upload*/
  .depart-upload-img{
    width: 1.6rem;
    height: 1.75rem;
    margin: 0 auto;
  }
  .depart-upload-img2{
    width: 1.6rem;
    height: 1.05rem;
    margin: 0 auto;
  }
  /* content */
  .content-item{
    padding-left: .15rem;
    padding-right: .15rem;
    padding-top: .15rem;
    padding-bottom: .15rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  .content-item>img{
    width: .06rem;
    height: .1rem;
    margin-right: .03rem;
  }
  .content-item>img.up{
    transform: rotate(270deg);
  }
  .content-item>img.down{
    transform: rotate(90deg);
  }
</style>
